﻿<cfscript>
/** 
* DataBase Frameworks - Sequence
* 
* @hint "DataBase Frameworks - Sequence - StudentChange" 
*/ 

component 
	displayname="public.service.db.senate.sequence.StudentChange" 
	output=false 
	accessors=true 
	{

	
	/**
	* @hint "初始化对象"
	*/
	public function init() output=false {
		return this;
	}
	
	/**
	* @hint "自定义主键规则"
	*/
	public string function getID() output=false {
		
		var nextID = year(now()) & numberFormat(1, "0_____");
		
		var sql = "SELECT a.stuchg_id 
					FROM t_stuchange a 
					WHERE a.stuchg_id LIKE :condition 
					ORDER BY a.stuchg_id DESC";

		var queryObj = new Query(datasource = application.dnsMaster, maxRows = 1);
		queryObj.addParam( name="condition", value= year(now()) & "______", cfsqltype="cf_sql_char" );
		var rs_check = queryObj.execute(sql = sql).getResult();
		/* 
			主键生成规则 
			
			异动代码为10位, 4位年份 余下6位为流水号
		*/
		if (rs_check.recordCount) {
			/* 创建一个追加id */
			nextID = year(now()) & numberFormat((right(rs_check["stuchg_id"][1], 6) + 1), "0_____");
			
		}

		return nextID;
		
	}

}

</cfscript>